<template>
	<view class="pb40">
		<u-navbar :title="title"></u-navbar>
		<view class="" style="height: 100rpx;">
			<image src="../../static/toubu.png" mode="widthFix" class="wd100"
				style="box-shadow:0rpx 6rpx 10rpx -8rpx #666;"></image>
		</view>
		<view class="pos-rel">
			<image src="../../static/bg.png" mode="widthFix" class="pos-abs wd100" style="z-index: -1;"></image>
			<view class="dis-flex flex-center mt30">
				<view  class="center c-666 br5 fw600 fs20"
					style="width: 300rpx;height: 80rpx;line-height: 80rpx;letter-spacing:4rpx; ">
					订单金额
				</view>
				<view  class="center  br5 fw600 fs20"
					style="width: 300rpx;height: 80rpx;line-height: 80rpx;letter-spacing:4rpx; ">
					预付定金
				</view>
			</view>
			<view class="dis-flex flex-center ">
				<view  class="center c-666 br5 fw600 fs18"
					style="width: 280rpx;height: 60rpx;line-height: 60rpx;">
					¥{{data.money}}
				</view>
				<view  class="center  br5 fw600 fs18"
					style="width: 280rpx;height: 60rpx;line-height: 60rpx;">
					¥{{dingjin}}
				</view>
			</view>
			
			<view class="fs10 pr30 pl30 mt20">
				<rich-text :nodes="paytext"></rich-text>
				<view class="mt20 dis-flex flex-align-center">
					<u-checkbox-group width="50rpx">
						<u-checkbox v-model="checked" shape="circle"></u-checkbox>
					</u-checkbox-group>
					<view class="fs12 c-999">
						阅读并同意中检的<text @click="goxieyi" style="border-bottom: 2rpx solid #999999;">《车辆检测委托协议》</text> 
					</view>
				</view>
				<view class="dis-flex flex-center mt25">
					<view @click="gopay" class="center c-fff br5 fw600 fs20"
						style="width: 260rpx;height: 90rpx;line-height: 90rpx;letter-spacing:4rpx; background-color: #00aeff;box-shadow:4rpx 6rpx 10rpx -8rpx #666;">
						立即支付
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '一检验车',
				data:[],
				dingjin:'0.00',
				suo:true,
				checked:false,
				header:'',
				paytext:'',

			}
		},
		onLoad(e) {
			this.data = JSON.parse(decodeURIComponent(e.data));
			this.init()
		},
		methods: {
			init(){
				//获取预付定金
				this.$http.post(this.$config.UrlPostdeposit, {}).then((res) => {
					if (res.status == 1) {
						this.dingjin = res.data.price
						this.header = res.data.header
						this.paytext = res.data.paytext
					}
				})
			},
			gaibian(index) {
				this.tab = index
			},
			godidian() {
				this.didian_show = !this.didian_show
			},
			goxieyi(){
				this.$api.openWindow("/pages/content/content")
			},
			gochexing() {
				this.chexing_show = !this.chexing_show
			},
			//微信支付
			gopay() {
				if(this.checked == false){
					this.$api.toast('请阅读协议并同意')
					return;
				}
				var that = this
				if(that.suo){
					that.suo = false
					that.$http.post(that.$config.UrlPostcreateOrder, that.data).then((res) => {
						//生成订单成功
						if (res.status == 1) {
							var json={
								uid:uni.getStorageSync('uid'),
								oid:res.data.id
							}
							that.$http.post(that.$config.UrlPostpayFunc, json).then((res) => {
								var data = res.data
								uni.requestPayment({
									provider: 'wxpay',
									timeStamp: data.timeStamp,
									nonceStr: data.nonceStr,
									package: data.package,
									signType: 'MD5',
									paySign: data.paySign,
									success: function(res) {
										//支付成功后获取数据信息，跳转支付成功页面
										that.$api.toast('支付成功')
										that.suo = true
										setTimeout(()=>{
											that.$api.openWindow('/pages/order/order?tag=2','redirectTo')
										},500)
									},
									fail: function(err) {
										console.log(err)
										that.suo = true
										that.$api.toast('支付失败')
										setTimeout(()=>{
											that.$api.openWindow('/pages/order/order?tag=1','redirectTo')
										},500)
									}
								});
							})
						}
					})
				}
				
			}
		}
	}
</script>

<style>
	page {
		background: #ffffff;
		color: #333333;
	}
</style>
